package com.gemantic.auth.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class TokenSession implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1389029815445723412L;

	private String userName;
	
	private String token;
	
	private boolean tokenFlag;
	
	private long deadline;
	
	private List<String> addressList;
	
	public TokenSession(String token,String userName) {
		this.userName = userName;
		this.token=token;
		this.tokenFlag=false;//令牌默认无效
		this.deadline = System.currentTimeMillis()+10*60*1000;
		this.addressList=new ArrayList<String>();
	}
	
	public TokenSession() {
		super();
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public long getDeadline() {
		return deadline;
	}

	public void setDeadline(long deadline) {
		this.deadline = deadline;
	}

	public List<String> getAddressList() {
		return addressList;
	}

	public void setAddressList(List<String> addressList) {
		this.addressList = addressList;
	}

	public boolean isTokenFlag() {
		return tokenFlag;
	}

	public void setTokenFlag(boolean tokenFlag) {
		this.tokenFlag = tokenFlag;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Override
	public String toString() {
		return "TokenSession [userName=" + userName + ", token=" + token + ", tokenFlag=" + tokenFlag + ", deadline="
				+ deadline + ", addressList=" + addressList + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((addressList == null) ? 0 : addressList.hashCode());
		result = prime * result + (int) (deadline ^ (deadline >>> 32));
		result = prime * result + ((token == null) ? 0 : token.hashCode());
		result = prime * result + (tokenFlag ? 1231 : 1237);
		result = prime * result + ((userName == null) ? 0 : userName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TokenSession other = (TokenSession) obj;
		if (addressList == null) {
			if (other.addressList != null)
				return false;
		} else if (!addressList.equals(other.addressList))
			return false;
		if (deadline != other.deadline)
			return false;
		if (token == null) {
			if (other.token != null)
				return false;
		} else if (!token.equals(other.token))
			return false;
		if (tokenFlag != other.tokenFlag)
			return false;
		if (userName == null) {
			if (other.userName != null)
				return false;
		} else if (!userName.equals(other.userName))
			return false;
		return true;
	}
	
}
